import {
  defineConfig
} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx';
import path from 'path';
import appConfig from './public/static/app-config.json'

const {
  BASE_API: {
    host,
    port
  }
} = appConfig;

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx()
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@assets': path.resolve(__dirname, './src/assets'),
      '@comps': path.resolve(__dirname, './src/components'),
      '@api': path.resolve(__dirname, './src/api'),
    }
  },
  server: {
    proxy: {
      '/api': {
        target: `${host}:${port}`,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
    }
  }
})